<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-group lvGutter="20px" class="aui-gutter-column-lg">
    <span class="aui-text-label">
        {{'protection_selected_copy_label' | i18n}}
    </span>
    <span>
        {{ rowCopy.display_timestamp | date: 'yyyy-MM-dd HH:mm:ss'}}
    </span>
</lv-group>
<ng-container *ngIf="rowCopy.isSearchRestore; else elseTemplate">
    <div class="aui-gutter-column-md">
        <lv-group lvGutter="20px" class="padding-10">
            <span class="aui-text-label">
                {{'protection_selected_file_label' | i18n}}
            </span>
            <span>{{ rowCopy.searchRestorePath | nil }}</span>
        </lv-group>
    </div>
</ng-container>
<ng-template #elseTemplate>
    <aui-file-tree [copy]="rowCopy" [treeData]="originalFileData" (tableSelectionChange)="tableSelectionChange($event)"
        (treeExpandedChange)="getCopySourceTree($event)" #fileTree></aui-file-tree>
</ng-template>

<!-- 恢复配置 -->
<h3 class="aui-gutter-column-sm">
    {{'protection_restore_file_config_label' | i18n}}
</h3>
<ng-container [ngSwitch]="childResType">
    <ng-container *ngSwitchCase="dataMap.Resource_Type.virtualMachine.value">
        <aui-file-restore [rowCopy]="rowCopy" [childResType]="childResType" fileLevelRestore="true"
            (restoreParamsChange)="restoreParamsChange($event)"></aui-file-restore>
    </ng-container>
    <ng-container *ngSwitchDefault>
        <lv-form [formGroup]="formGroup" [lvLabelColon]="false" class="formGroup">
            <lv-form-item>
                <lv-form-label lvRequired>{{'protection_restore_to_label' | i18n}}</lv-form-label>
                <lv-form-control>
                    <lv-radio-group formControlName="restoreLocation">
                        <lv-group [lvGutter]="'30px'">
                            <lv-radio
                                [lv-tooltip]="disableOriginLocation?('protection_cloud_origin_restore_disabled_label'| i18n):''"
                                [lvDisabled]="disableOriginLocation" [lvValue]="restoreLocationType.ORIGIN">
                                {{'common_restore_to_origin_location_label' | i18n}}
                            </lv-radio>
                            <lv-radio [lvValue]="restoreLocationType.NEW">
                                {{'common_restore_to_new_location_label' | i18n}}
                            </lv-radio>
                        </lv-group>
                    </lv-radio-group>
                </lv-form-control>
            </lv-form-item>

            <ng-container *ngIf="formGroup.value.restoreLocation === restoreLocationType.ORIGIN">
                <lv-form-item>
                    <lv-form-label>{{'protection_computer_location_label' | i18n}}</lv-form-label>
                    <lv-form-control>
                        <span>{{formGroup.value.location | nil}}</span>
                    </lv-form-control>
                </lv-form-item>
                <lv-form-item>
                    <lv-form-label lvRequired>
                        {{ (isCloudResource(childResType) ?
                        'protection_restore_cloud_ip_label' : 'protection_restore_vm_ip_label') | i18n}}
                        <i *ngIf="![dataMap.Resource_Type.openStackCloudServer.value,dataMap.Resource_Type.hyperVVm.value].includes(childResType)"
                            lv-icon="aui-icon-help" lv-tooltip="{{ (childResType === dataMap.Resource_Type.HCSCloudHost.value ?
                            'common_hcs_vm_ip_help_label' : 'common_vmtools_help_label') | i18n}}"
                            lvTooltipPosition="rightTop" lvTooltipTheme="light" class="configform-constraint"
                            lvColorState='true'></i>
                    </lv-form-label>
                    <lv-form-control>
                        <ng-container *ngTemplateOutlet="vmIpTpl"></ng-container>
                    </lv-form-control>
                </lv-form-item>
            </ng-container>
            <ng-container *ngIf="formGroup.value.restoreLocation === restoreLocationType.NEW">
                <ng-container [ngSwitch]="childResType">
                    <ng-container *ngSwitchCase="dataMap.Resource_Type.HCSCloudHost.value">
                        <lv-form-item>
                            <lv-form-label lvRequired>
                                {{'common_target_cloud_platform_label' | i18n}}
                            </lv-form-label>
                            <lv-form-control>
                                <lv-select formControlName="targetCloudPlatform"
                                    [lvOptions]="targetCloudPlatformOptions" lvValueKey="value" lvShowFilter
                                    lvFilterKey="label" lvFilterMode="contains">
                                </lv-select>
                            </lv-form-control>
                        </lv-form-item>
                        <lv-form-item>
                            <lv-form-label lvRequired>
                                {{'common_cloud_platform_tenant_label' | i18n}}
                            </lv-form-label>
                            <lv-form-control>
                                <lv-select formControlName="cloudPlatformTenant"
                                    [lvOptions]="cloudPlatformTenantOptions" lvValueKey="value" lvShowFilter
                                    lvFilterKey="label" lvFilterMode="contains">
                                </lv-select>
                            </lv-form-control>
                        </lv-form-item>
                        <lv-form-item>
                            <lv-form-label lvRequired>
                                {{'system_area_label' | i18n}}
                            </lv-form-label>
                            <lv-form-control>
                                <lv-select formControlName="regions" [lvOptions]="regionsOptions" lvValueKey="value"
                                    lvShowFilter lvFilterKey="label" lvFilterMode="contains">
                                </lv-select>
                            </lv-form-control>
                        </lv-form-item>
                        <lv-form-item>
                            <lv-form-label lvRequired>
                                {{'common_project_resource_label' | i18n}}
                            </lv-form-label>
                            <lv-form-control>
                                <lv-select formControlName="projects" [lvOptions]="projectsOptions" lvValueKey="value"
                                    lvShowFilter lvFilterKey="label" lvFilterMode="contains">
                                </lv-select>
                            </lv-form-control>
                        </lv-form-item>
                        <lv-form-item>
                            <lv-form-label lvRequired>
                                {{'common_cloud_server_label' | i18n}}
                            </lv-form-label>
                            <lv-form-control>
                                <lv-select formControlName="cloudHost" [lvOptions]="cloudHostOptions" lvValueKey="value"
                                    lvShowFilter lvFilterKey="label" lvFilterMode="contains">
                                </lv-select>
                            </lv-form-control>
                        </lv-form-item>
                    </ng-container>

                    <ng-container *ngSwitchCase="dataMap.Resource_Type.openStackCloudServer.value">
                        <lv-form-item>
                            <lv-form-label lvRequired>{{'protection_volume_restore_target_label' |
                                i18n}}</lv-form-label>
                            <lv-form-control>
                                <lv-tree-select [lvTreeData]="serverTreeData" lvTreeSelectionMode="single"
                                    formControlName="targetServer" lvShowClear lvTreeShowLine
                                    (lvExpandedChange)="openstackExpandedChange($event)" lvShowFilter
                                    lvFilterKey="label" lvFilterMode="contains">
                                    <lv-treeselect-trigger>
                                        <span>{{ formGroup.value.targetServer[0]?.path | nil }}</span>
                                    </lv-treeselect-trigger>
                                </lv-tree-select>
                                <p class="aui-text-help-sm" style="line-height: 0.18rem">
                                    <i lv-icon="lv-icon-status-info" lvColorState='true' style="margin-right: 8px"></i>
                                    <span>{{'protection_openstack_filelevel_restore_tip_label' | i18n}}</span>
                                </p>
                            </lv-form-control>
                        </lv-form-item>
                    </ng-container>

                    <ng-container *ngSwitchCase="dataMap.Resource_Type.APSCloudServer.value">
                        <lv-form-item>
                            <lv-form-label lvRequired>{{'protection_volume_restore_target_label' |
                                i18n}}</lv-form-label>
                            <lv-form-control>
                                <lv-tree-select [lvTreeData]="serverTreeData" lvTreeSelectionMode="single"
                                    formControlName="targetServer" lvShowClear lvTreeShowLine
                                    (lvExpandedChange)="apsExpandedChange($event)" lvShowFilter lvFilterKey="label"
                                    lvFilterMode="contains">
                                    <lv-treeselect-trigger>
                                        <span>{{ formGroup.value.targetServer[0]?.path | nil }}</span>
                                    </lv-treeselect-trigger>
                                </lv-tree-select>
                            </lv-form-control>
                        </lv-form-item>
                    </ng-container>

                    <ng-container *ngSwitchDefault>
                        <lv-form-item>
                            <lv-form-label lvRequired>
                                {{ 'common_target_compute_position_label' | i18n }}
                                <i lv-icon="aui-icon-help"
                                    lv-tooltip="{{'protection_computer_location_help_label' | i18n}}"
                                    lvTooltipPosition="rightTop" lvTooltipTheme="light" class="configform-constraint"
                                    lvColorState='true'></i>
                            </lv-form-label>
                            <lv-form-control>
                                <lv-select formControlName="environment" [lvOptions]="environmentOptions"
                                    lvValueKey="key" lvShowFilter lvFilterKey="label" lvFilterMode="contains"
                                    lvPlaceholder="{{'common_select_virtual_environment_label'|i18n}}">
                                </lv-select>
                            </lv-form-control>
                        </lv-form-item>
                        <lv-form-item>
                            <lv-form-label></lv-form-label>
                            <lv-form-control>
                                <lv-tree-select [lvTreeData]="vmTreeData" lvTreeSelectionMode="single"
                                    formControlName="vm" lvShowClear lvTreeShowContentIcon
                                    lvPlaceholder="{{'protection_computer_location_disk_tip_label'|i18n}}"
                                    lvVirtualScroll (lvExpandedChange)="expandedChange($event)" lvShowFilter
                                    lvFilterKey="label" lvFilterMode="contains">
                                </lv-tree-select>
                            </lv-form-control>
                        </lv-form-item>
                    </ng-container>

                </ng-container>
                <lv-form-item>
                    <lv-form-label lvRequired>
                        {{ (isCloudResource(childResType) ?
                        'protection_restore_cloud_ip_label' : 'protection_restore_vm_ip_label') | i18n}}
                        <i *ngIf="![dataMap.Resource_Type.openStackCloudServer.value,dataMap.Resource_Type.hyperVVm.value].includes(childResType)"
                            lv-icon="aui-icon-help" lv-tooltip="{{ (childResType === dataMap.Resource_Type.HCSCloudHost.value ?
                            'common_hcs_vm_ip_help_label' : 'common_vmtools_help_label') | i18n}}"
                            lvTooltipPosition="rightTop" lvTooltipTheme="light" class="configform-constraint"
                            lvColorState='true'></i>
                    </lv-form-label>
                    <lv-form-control>
                        <ng-container *ngTemplateOutlet="vmIpTpl"></ng-container>
                    </lv-form-control>
                </lv-form-item>
            </ng-container>
            <!-- 操作系统放前面 -->
            <lv-form-item
                *ngIf="[dataMap.Resource_Type.openStackCloudServer.value,dataMap.Resource_Type.hyperVVm.value].includes(childResType)">
                <lv-form-label lvRequired>
                    {{'protection_os_type_label' | i18n}}
                </lv-form-label>
                <lv-form-control [lvErrorTip]="requiredErrorTip">
                    <lv-select formControlName="osType" [lvOptions]="osTypeOptions" lvValueKey="value">
                    </lv-select>
                </lv-form-control>
            </lv-form-item>
            <!-- 新增端口 -->
            <lv-form-item *ngIf="showPort()">
                <lv-form-label lvRequired>
                    {{ 'common_port_label' | i18n }}
                </lv-form-label>
                <lv-form-control [lvErrorTip]="portErrorTip">
                    <input lv-input type="text" formControlName="port" placeholder="1~65535" />
                </lv-form-control>
            </lv-form-item>
            <lv-form-item>
                <lv-form-label lvRequired>
                    {{(isCloudResource(childResType) ? 'protection_restore_cloud_user_label'
                    : 'protection_restore_vm_user_label') | i18n}}
                </lv-form-label>
                <lv-form-control [lvErrorTip]="requiredErrorTip">
                    <input lv-input type="text" formControlName="userName" autocomplete="new-password" />
                </lv-form-control>
            </lv-form-item>
            <lv-form-item>
                <lv-form-label lvRequired>
                    {{(isCloudResource(childResType) ?
                    'protection_restore_cloud_password_label' : 'protection_restore_vm_password_label') | i18n}}
                </lv-form-label>
                <lv-form-control [lvErrorTip]="requiredErrorTip">
                    <aui-inupt-with-eye formControlName="password" [lvPasteAllowed]="false"></aui-inupt-with-eye>
                </lv-form-control>
            </lv-form-item>
            <lv-form-item>
                <lv-form-label lvRequired>{{'protection_over_write_rule_label' | i18n}}</lv-form-label>
                <lv-form-control>
                    <lv-radio-group formControlName="originalType" style="margin-top:8px;">
                        <lv-group [lvGutter]="'20px'" lvDirection='vertical' class="mgt-8">
                            <lv-radio [lvValue]="vmFileReplaceStrategy.Overwriting">
                                {{'protection_overwrite_label' | i18n}}
                            </lv-radio>
                            <lv-radio [lvValue]="vmFileReplaceStrategy.Skip">
                                {{'protection_skip_label' | i18n}}
                            </lv-radio>
                            <lv-radio [lvValue]="vmFileReplaceStrategy.Replace">
                                {{'protection_restore_replace_older_label' | i18n}}
                            </lv-radio>
                        </lv-group>
                    </lv-radio-group>
                </lv-form-control>
            </lv-form-item>
        </lv-form>
    </ng-container>
</ng-container>

<ng-template #vmIpTpl>
    <ng-container [formGroup]="formGroup">
        <lv-radio-group formControlName="vmIpType">
            <lv-group [lvGutter]="'20px'">
                <lv-radio [lvValue]="vmIpTypeOptions.exist">
                    {{'protection_vm_restore_select_ip_label' | i18n}}
                </lv-radio>
                <lv-radio [lvValue]="vmIpTypeOptions.custom">
                    {{'protection_vm_restore_input_ip_label' | i18n}}
                </lv-radio>
            </lv-group>
        </lv-radio-group>
        <ng-container *ngIf="formGroup.value.vmIpType === vmIpTypeOptions.exist; else elseVmIpTemplate">
            <lv-form-control class="ip-control">
                <lv-select formControlName="vmIp" [lvOptions]='vmIpOptions' lvValueKey="value" [lvPlaceholder]="(vmIpNoData?'protection_restore_vm_ip_select_placeholder_label' :
                    'protection_restore_vm_ip_placeholder_label') | i18n" lvShowFilter lvFilterMode="contains"
                    lvFilterKey='label'>
                </lv-select>
            </lv-form-control>
        </ng-container>
        <ng-template #elseVmIpTemplate>
            <lv-form-control class="ip-control" [lvErrorTip]="ipErrorTip">
                <input lv-input type="text" formControlName="customIp" />
            </lv-form-control>
        </ng-template>
    </ng-container>
</ng-template>

<ng-template #footerTpl>
    <div class="lv-modal-btns">
        <lv-group lvGutter='8px'>
            <button lv-button lvType='primary' (click)='testConnection()' [disabled]='formGroup.invalid  || disabled'
                [lvLoading]='testLoading'>
                {{ 'common_test_label' | i18n }}
            </button>
            <button lv-button lvType='primary' (click)='onOK()' [disabled]='formGroup.invalid || disabled || !isTest'
                [lvLoading]='okLoading'>
                {{ 'common_ok_label' | i18n }}
            </button>
            <button lv-button (click)='modal.close()'>
                {{ 'common_cancel_label' | i18n }}
            </button>
        </lv-group>
    </div>
</ng-template>